package com.hanter.android.radlib.countdown.impl;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import androidx.annotation.Nullable;

public class TimerSqlOpenHelper extends SQLiteOpenHelper {

    private static final int DB_VERSION = 2;
    private static final String DB_NAME = "count_down_timers.db";

    static final String TABLE_TIMERS = "count_down_timers";

    static final String COLUMN_TIMER_ID = "timer_id";
    static final String COLUMN_TIMER_NAME = "timer_name";
    static final String COLUMN_TIMER_GROUP = "timer_group";
    static final String COLUMN_INTERVAL = "interval";
    static final String COLUMN_START_TIME = "start_time";
    static final String COLUMN_FINISH_TIME = "finish_time";
    static final String COLUMN_STATUS = "status";

    private static final String TABLE_CREATE =
            "CREATE TABLE " + TABLE_TIMERS + " (" + COLUMN_TIMER_NAME + " TEXT(50), " +
                    COLUMN_TIMER_GROUP + " TEXT(50), " +
                    COLUMN_INTERVAL + " BIGINT, " +
                    COLUMN_START_TIME + " BIGINT, " +
                    COLUMN_FINISH_TIME + " BIGINT, " +
                    COLUMN_STATUS + "status TEXT(20), " +
                    "CONSTRAINT " + COLUMN_TIMER_ID + " PRIMARY KEY (" +
                    COLUMN_TIMER_NAME +
                    ", " +
                    COLUMN_TIMER_GROUP +
                    "));";

    public TimerSqlOpenHelper(@Nullable Context context) {
        super(context, DB_NAME, null, DB_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(TABLE_CREATE);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        // 升级
    }
}
